﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Compilex.Automata;
using Compilex.BaseLibrary;

namespace Compilex.Lexer.Automata
{
    public class OperatorDFA : DFA
    {
       public String Operator { get; protected set; }
       public OperatorDFA(String op)
            : base() // será setado no construtor
        {
            ThrowHelper.ThrowIfNullOrEmpty(op);
            this.Operator = op;
            this.StartState = BuildAutomaton(op);
        }

       private DFAState BuildAutomaton(string op)
        {
            DFAState startState = new DFAState("startState");
            DFAState prevState = startState;
            for (int i = 0; i < op.Length; i++)
            {
                DFAState nextState = new DFAState("q" + i);
                prevState.AddTransition(op[i], nextState);
                prevState = nextState;
            }
            prevState.IsAcceptState = true;
            return startState;
        }
    }
}
